
///构建查询区
AI.FilterArea = Event.$extend({
	id:'FilterArea',
	hovertype:'hover',//fit
	containerId:'advance_filterarea',
	options:null,
	__init__ : function(options) {
		if(options.containerId) this.containerId=options.containerId;
		if(options.hovertype) this.hovertype=options.hovertype;
		this.init(options);
	},

	init:function(options){
		this.options=options;
		var html=this.getDataHtml();
		$("#"+this.containerId).empty().append(html);
		this.bindEvent();
	},
	onChange:function(){
		var wheres=[];
		var vals=[];
		var configItems=this.options.configItems;
		for(var i=0;i<configItems.length;i++ ){
			var item=configItems[i];
			if(item.type=="text"){
				var selval=$("#"+this.containerId+" .media-body#"+item.code+" input").val();
				if(selval){
					wheres.push(item.where.replace("{selfval}",selval));
					vals.push(item.code,selval);
				};
			}else{
				var allSelItems=$("#"+this.containerId+" .media-body#"+item.code+" a.active.all");
				if(allSelItems.length>0){console.log(item.code+"select all");continue;};//该项查询条件为所有
				var allSelItems=$("#"+this.containerId+" .media-body#"+item.code+" a.active");
				var selId=[],selVal=[];
				for(var j=0;j<allSelItems.length;j++){
					selId.push($(allSelItems[j]).attr("id"));
					selVal.push($(allSelItems[j]).html());
				}
				if(selId.length>0){
					wheres.push(item.where.replace("{selfval}",selId.join("','")));
					vals.push({selId:selId.join(","),selVal:selVal.join(",")});
				}
			}
		};
		console.log(wheres);
		console.log(vals);
		if(this.options.onChange){
			this.options.onChange(wheres,vals);
		}
		
	},
	bindEvent:function(){
	var self=this;
	$("#"+this.containerId+" .media-body a").click(function(){
		if($(this).hasClass("all")){
			$(this).parent().parent().find("a.active").removeClass("active");
			$(this).addClass("active");
		}
		else{
			$(this).parent().parent().find("a.all").removeClass("active");
			$(this).toggleClass("active"); 
		}
		self.onChange();
	});
	$("#"+this.containerId+" .media-body input").change(function(){
		self.onChange(); 
	});
	if(this.hovertype=="hover"){
		$("#"+this.containerId).hover(function() {
		},
		function() {
			$(this).hide();
		});
	}
	//子节点
	var configItems=this.options.configItems;
	for(var i in configItems){
		if(configItems[i].childWhere && configItems[i].childStoreSql){
			var itemCode = configItems[i].code;
			$("#" + itemCode + ">ul a").click(function(){
				$("#" + itemCode +" a").removeClass("active");
				$(this).addClass("active");
			 	$('#' + itemCode +" div li" ).hide();
				$('#' + itemCode +' li[data-depend="' + $(this).attr("id") + '"]' ).show();
			// },function(){
			// 	$("#" + itemCode +" a").removeClass("active");
			// 	$('#' + itemCode +' li[data-depend="' + $(this).attr("id") + '"]' ).hide();
			})
		}
	}
	},
	getDataHtml:function(){
		var configItems=this.options.configItems;
		var paraItems=[];
		for(var i=0;i<configItems.length;i++ ){
			var item=configItems[i];
			if(item.storesql&& item.storesql.toLowerCase().indexOf("select ")>=0){
			  var para={paraname:item.code,paratype:'array',sql:item.storesql};
			  paraItems.push(para);
			}else{
				
			}
		}
		var sendObj = { paras:paraItems };
		var URL = '/' + contextUrl + '/olapquery?json=' + ai.encode(sendObj);
		var obj = ai.remoteData(URL);
		if(!obj || !obj.root) return;
		var html="";
		for(var i=0;i<configItems.length;i++ ){
			var item=configItems[i];
			html+='<article class="media" > <a class="media-left pull-left m-t-xs"><i class="glyphicon glyphicon-filter text-danger"></i><strong>'+item.name+'</strong></a>';
			html+=' <div class="media-body" id="'+item.code+'"> <ul>';
			if(item.type=='text'){
				html+='<li><input type="text"  class="input-sm form-control"></li>';
			}
			else{
				html+='<li><a class="active all" href="#" id="all">所有</a></li>';
				var dataItems=null;
				for(var j=0;j<obj.root.length;j++){
					if(obj.root[j][item.code]){ 
						var dataTmpList =obj.root[j][item.code]; 
						if(dataTmpList.length>0){
							var keyArray=[];
							for(key in dataTmpList[0]){
								keyArray.push(key);
							}
						};
						var key1,key2;
						if(keyArray.length>=2){
							key1=keyArray[0];
							key2=keyArray[1];
						}else{
							key1=keyArray[0];
							key2=keyArray[0]; 
						};
						dataItems=[];
						for(var k=0;k<dataTmpList.length;k++){
							var item=dataTmpList[k];
							dataItems.push({rowcode:item[key1],rowname:item[key2]}) 
						}
						break; 
					}
				};
				if(!dataItems && configItems[i].storesql){
					var itemArray = configItems[i].storesql.split(",");
					dataItems=[];
					for(var k=0;k<itemArray.length;k++){
						dataItems.push({rowcode:itemArray[k],rowname:itemArray[k]})
					} 
				};
				if(dataItems){
					for(var k=0;k<dataItems.length;k++){
						html+='<li><a href="#" id="'+dataItems[k].rowcode+'">'+dataItems[k].rowname+'</a></li>'
					}
				}
			}
			html+='</ul>';
			if(configItems[i].childWhere && configItems[i].childStoreSql){
				html += '<div><ul>';
				var childStore = ai.getJsonStore(configItems[i].childStoreSql);
				var childRecord;
				for(var ii = 0; ii < childStore.getCount(); ii ++){
					childRecord = childStore.getAt(ii);
					html += '<li data-depend="' + childRecord.get("PARENTCODE") + '" style="display:none;">' + 
							'<a href="#" id="' + childRecord.get("RULECODE") + '">' +
							childRecord.get("RULENAME") + '</a></li>';
				}
				html += '</ul></div>';
			}
			html+='</div></article> ';
		}
		html+='<div class="btn-group m-b-sm pull-right" style="margin-top:10px"> <button type="button" class="btn btn-success">查询</button> <button type="button" class="btn" style="margin-left:10px;margin-right:10px">重置</button> <button type="button" class="btn">退出</button>  </div>';
		//html+='<ul class="nav navbar-nav pull-right"><li><a href="#" class="btn-info">查询</a><li><li><a href="#" class="btn-info">重置</a><li></ul>';
		return html;
		//     if(obj.root &&obj.root.length)  metaModel = {metaInfo:obj.root[0].objinfo,attrArray:obj.root[1].objattr,actionItems:{},objproperty:obj.root[2].objproperty};
	}
});
AI.FlatTree = Event.$extend({
	id:'flattree',
	containerId:'',
	firstCode:'',//第一个由URL地址的节点
	firstUrl:'',//第一个由URL地址的节点
	showPop:true,///是否展示hover的菜单
	onTreeClick:null,
	__init__ : function(options) {
		if(options.onTreeClick) this.onTreeClick=options.onTreeClick;
		this.init(options);
	},
	init:function(options){
		$("#"+options.containerId).empty().append(this.flattree_html);
		var data;
		if(options.dataurl){
			data=this.getFlatData(options.dataurl);
		}
		else if(options.data){
			data=options.treedata;
		}
		else if(options.loadtype){
			data=this.getFlatData(options.loadtype);
		}
		else  data=this.getFlatData();
		
	 	$.template('template', this.flattree_tpl); 
	 	$.tmpl('template', data).appendTo('#flatindexmenu');
	 	
	 	if(options.showpop==false){
	 		$("#flatindexmenu .pop").remove();
	 	}
	 	this.bindEvent();
	},
	getFirstNodeInfo:function(){
		return {firstCode:this.firstCode,firstUrl:this.firstUrl}
	},
	getFlatData:function (loadtype){
		var self=this;
		function getPopItemSubItems(parentCode,popItem){
			for(var i=0;i<modelStore.getCount();i++){
				   var r=modelStore.getAt(i);
				   if(r.get("PARENTCODE")!=parentCode) continue;
				   var item={itemid:r.get("MODELCODE"),
						     itemtitle:r.get("MODELNAME").substr(0,4),
						     url:dealUrl(r.get("URL")),
						     objtype:r.get("MODELTYPE"),
						     filter:r.get("COUNTSQL"),
						     subitems:[]
				   };
				   self.extendItemInfo(item,loadtype);
				   
				   popItem.subitems.push(item);
				   
				   if(!self.firstCode && r.get("URL")){
					   self.firstCode=r.get("MODELCODE");
					   self.firstUrl=r.get("URL");
				   };
				   
				   getPopItemSubItems(r.get("MODELCODE"),popItem);
		    }
		}
		function getChildData(parentCode,parentItem){
			var leftitem=null;
			var popitem=null;
			for(var i=0;i<modelStore.getCount();i++){
				   var r=modelStore.getAt(i);
 
				   if(r.get("PARENTCODE")!=parentCode) continue;
				   if(!leftitem){
					   leftitem={id:r.get("MODELCODE"),title:"", subitems:[]}; 
				   };
				   
				   if(!self.firstCode && r.get("URL")){
					   self.firstCode=r.get("MODELCODE");
					   self.firstUrl=r.get("URL");
				   }
				   var item={itemid:r.get("MODELCODE"),
						     itemtitle:r.get("MODELNAME"),
						     url:dealUrl(r.get("URL")),
						     objtype:r.get("MODELTYPE"),
						     filter:r.get("COUNTSQL"),
						     subitems:[]
				   };
				   
				   self.extendItemInfo(item,loadtype);
				   
//				   if(leftitem.subitems.length<9) 
					   leftitem.subitems.push(item);
				   //popitem={itemid:r.get("MODELCODE"),poptitle:r.get("MODELNAME"),subitems:[]};
				   getPopItemSubItems(r.get("MODELCODE"),item);
				   parentItem.popitems.push(item);  
		    };
		    if(leftitem){
		      leftitem.itemtitle="";
			  parentItem.leftitems.push(leftitem);
		    }
		};
		var metamodelSql="select modelcode,modelname,modeltype,parentcode,images ,classtype,remark,URL,COUNTSQL from metamodel where state = 'on' "
		    +" and (modelcode like '"+paramMap.prodcode+"%') and modelcode in (select modelcode  from METAPERMISSION where PERMISSIONLEVEL>='2' and groupcode in ( select a.groupcode from metagroupuser a,metagroup b where a.groupcode = b.groupcode and  username='" + _UserInfo.username + "'))"
		    +" order by seq,modelcode";
	    if(loadtype=="metaindex"){
	    	paramMap.prodcode='META';
	    	metamodelSql="select OBJTYPE modelcode,OBJNAME modelname,OBJTYPE modeltype,parentcode,'' URL from metaobjmodel order by ordseq";
	    }
	    else if(loadtype=="dataresindex"){
	    	paramMap.prodcode='2015110411162510000';
	    	metamodelSql="select RULECODE modelcode,RULENAME modelname,'TAB' modeltype,PARENTCODE,'' URL from metadb_struct where dbname='ZJ_HDFS'";
	    }
	    else if(loadtype=="dataastindex"){
	    	paramMap.prodcode='';
	    	metamodelSql="select RULECODE modelcode,RULENAME modelname,'TAB' modeltype,PARENTCODE,'' URL from metadb_struct where dbname='Hadoop'";
	    }
	    else if(loadtype=="dataservindex"){
	    	paramMap.prodcode='';
	    	metamodelSql="select RULECODE modelcode,RULENAME modelname,'TAB' modeltype,PARENTCODE,'' URL from metadb_struct where dbname='METADB'";
	    }
	    else if(loadtype){
	    	ai.loadRemotJsCss("/"+contextPath+"/dacp-res/js/"+loadtype+".js");
	    	return treedata;
	    }
	    
		var modelStore = new AI.JsonStore({
			sql:metamodelSql,
			pageSize:-1
		});
		 
		var data=[];
		for(var i=0;i<modelStore.getCount();i++){
		   var r=modelStore.getAt(i);
		   if(r.get("PARENTCODE")!=paramMap.prodcode) continue;
		   var item={itemid:r.get("MODELCODE"),
			   itemtitle:r.get("MODELNAME"),
			   url:dealUrl(r.get("URL")),
			   objtype:r.get("MODELTYPE"),
			   filter:r.get("COUNTSQL"),
			   leftitems:[],
			   popitems:[]
		   };
		   
		   this.extendItemInfo(item,loadtype);
		   
		   if(!this.firstCode && item.url) {
			   self.firstCode=r.get("MODELCODE");
			   self.firstUrl=r.get("URL");
		   }
		   getChildData(r.get("MODELCODE"),item);
		   data.push(item);
		};
		return data;
	},
	extendItemInfo:function(item,loadtype){
		if(loadtype=="metaindex"){
			var objtype=item.objtype;
			item.url="/"+contextPath+"/ftl/dataindex/ai.datares.index?objtype="+item.objtype;
			//item.filter="objtype='"+objtype+"'"; 
		}
	},
	bindEvent:function(){
		var self=this;
		$("#flatindexmenu a").click(function(){
			$("#flatindexmenu a.active").removeClass("active");
			$(this).addClass("active");
			var id=$(this).attr("id");
			var url=$(this).attr("href");
			var objtype=$(this).attr("objtype");
			var filter=$(this).attr("filter");
			var title=$(this).html();
			if(self.onTreeClick) self.onTreeClick(id,title,url,objtype,filter);
			return false;
		});
	},
	flattree_html:['<div class="type-item  hc_lnav jslist selected" style="padding-left:0px;"> ',  	    
		   			 '	<div class="allbtn">', 
	  				 //'	<h2><a href="#"><strong>&nbsp;</strong>导航列表<i>&nbsp;</i></a></h2> ',
	  				 '	<ul style="" class="" id="flatindexmenu"></ul>',
	  				 '</div>'
	  				 ].join(""),
    flattree_tpl:[' <li class="${itemid}" objtype="${objtype}" filter="${filter}" >',
		          '      <div class="tx"> <a href="${url}" id="${itemid}" objtype="${objtype}" filter="${filter}" ><i class="glyphicon glyphicon-map-marker"></i>${itemtitle}</a> </div> ',
		          '      {{each leftitems}}',
		          '      <dl> ',
		          '        <dt> ${itemtitle} </dt> ',
		          '       <dd> ',
		          '       		{{each subitems}}',
		          '        			<a id="${itemid}" objtype="${objtype}" filter="${filter}" href="${url}">${itemtitle}</a> ',
		          '             {{/each}} ',
		          '       </dd> ',
		          '      </dl> ',
		          '       <div class="pop"> ',
		          '       <h3><a href="" objtype="${objtype}" filter="${filter}" >${itemtitle}</a></h3>',
		          '           {{each popitems}}',
		          '       		<dl> ',
		          '        			<dl>  ',
		          '        				<dt> ${itemtitle} </dt> ',
		          '         			<dd> ',
		          '         				{{each subitems}}',
		          '          				<a objtype="${objtype}" filter="${filter}" class="ui-link" id="${itemid}" href="${url}">${itemtitle}</a> ',
		          '          				 {{/each}}',
		          '         			</dd> ',
		          '        			</dl> ',
		          '       		</dl> ',
		          '       	 {{/each}}',
		          '      </div>',
		          '      {{/each}}',
		          '    </li>'].join("")
});
AI.GoJsTreeMap = Event.$extend({
	containerId : null,
	sql : null,///必须包含关键字:ID,PID,NAME,"select modelcode as ID,parentcode as PID,modelname as NAME from metamodel where modelcode like 'DAG-DQ%'",
	rootName:null,//树根节点名称,分组树时有用
	groupFieldArray:null,//分组组装数
	onTreeClick:null,
	__init__ : function(options) {
	  if (options.onTreeClick) this.onTreeClick = options.onTreeClick;
	  this.init(options);
	},
	init : function(options) {
		//ai.loadRemotJsCss("/"+contextPath+"/dacp-lib/gojs/go.js");
		$("#" + options.containerId).empty();
		this.buildTreeMap(options);
	},
	buildTreeMap : function(options) {
		var $ = go.GraphObject.make;  // for conciseness in defining templates
	    myDiagram =
	      $(go.Diagram, options.containerId,  // the DIV HTML element
	        { initialDocumentSpot: go.Spot.TopCenter,
	          initialViewportSpot: go.Spot.TopCenter });
 
	    var bluegrad = $(go.Brush, go.Brush.Linear, { 0: "white", 1: "skyblue" });
	    var greengrad = $(go.Brush, go.Brush.Linear, { 0: "white", 1: "green" });
	    var redgrad = $(go.Brush, go.Brush.Linear, { 0: "white", 1: "red" });
	    var yellowgrad = $(go.Brush, go.Brush.Linear, { 0: "yellow", 1: "orange" });
	    // define the Node template
	    myDiagram.nodeTemplate =
	      $(go.Node, go.Panel.Auto,
	        { isShadowed: false },
	        $(go.Shape, "RoundedRectangle",/*Rectangle*/
	          {  fill: bluegrad ,stroke: "black",stretch: go.GraphObject.Fill}, new go.Binding("fill"),
	              new go.Binding("stroke")),
	        $(go.Panel, go.Panel.Table,
	          { margin: 4, maxSize: new go.Size(140, NaN) },
	          $(go.RowColumnDefinition,
	            { column: 0,
	              stretch: go.GraphObject.Horizontal,
	              alignment: go.Spot.Left }),
	          $(go.TextBlock,
	            { row: 0, column: 0,
	              maxSize: new go.Size(110, NaN),
	              font: "bold 8pt sans-serif",
	              alignment: go.Spot.Top },
	            new go.Binding("text", "MODELNAME")),
	         $("TreeExpanderButton",
	            {  row: 1,
	            	alignment: go.Spot.Left,
	              "ButtonIcon.stroke": "blue",
	              "ButtonBorder.fill": "yellow" })
	         ));
	    myDiagram.linkTemplate =
	      $(go.Link,// go.Link.Orthogonal,
	        { routing: go.Link.Orthogonal,corner: 5,selectable: false },
	        $(go.Shape,{stroke: "gray",strokeWidth: 1}));  // the default black link shape
	   
	    /////取树节点的数据
	   var nodeArray=null;
	   if(options.groupFieldArray){
		   nodeArray = this.getNodeArray(rootName,options.sql,options.groupFieldArray); 
	   }
	   else{
		   nodeArray = this.getTreeNodeArray(options.sql);
	   }
	   console.log(nodeArray);
	   myDiagram.model =
	      $(go.TreeModel,
	        { nodeKeyProperty:'ID',
	        	name:'MODELNAME',
	        	nodeParentKeyProperty: "PID",  // this property refers to the parent node data
	          nodeDataArray:nodeArray });

	    myDiagram.layout =
	      $(go.TreeLayout,
	        { treeStyle: go.TreeLayout.StyleRootOnly,//go.TreeLayout.StyleLastParents,
	          angle: 90,
	          layerSpacing: 20,
	          alternateAngle: 0,
	          alternateAlignment: go.TreeLayout.AlignmentStart,
	          alternateNodeIndent: 10,
	          alternateNodeIndentPastParent: 1,
	          alternateNodeSpacing: 10,
	          alternateLayerSpacing: 10,
	          alternateLayerSpacingParentOverlap: 1,
	          alternatePortSpot: new go.Spot(0, 0.999, 20, 0),
	          alternateChildPortSpot: go.Spot.Left });
	      
	   myDiagram.addDiagramListener("ObjectDoubleClicked", function(e) {
	   	 var sel = e.diagram.selection;
	   	 if (sel.count === 0) return;
	   	 var elem = sel.first();
	      var elemData = elem.Em||elem.zm;
	      console.log(elemData);
	      var objid=elemData.id||elemData.MODELCODE;
	        
	    });
	    myDiagram.addChangedListener(function (e) {
	    });
	    
	},
	buildGroupTreeMap : function(rootName,querysql,groupfieldArray) {
		var ds_map = new AI.JsonStore({
		    sql: querysql,
		    pageSize:-1
		  });
		var nodeArray=[];
		var path={};
		var seq=10000;
		nodeArray.push({id:seq,NAME:rootName,pid:""});
		
		for(var i=0;i< ds_map.getCount();i++){
		 	  var r=ds_map.getAt(i);
		 	  var nodePath="",nodeName="";
		 	  var parentCode="";
		 	 for(var j=0;j<groupfieldArray.length;j++){
			 	  	nodename = r.get(groupfieldArray[j]);
			 	  	if(j==0) nodePath=nodename; 
			 	  	else nodePath+='-'+nodename;
			 	  	 
			 	    if(path[nodePath]) 
			 	  		  parentCode = path[nodePath]
			 	  	else{
			 	  			seq++;
			 	  			path[nodePath]=seq;
			 	  		    if (j==0 && !root) nodeArray.push({ID:seq,NAME:nodename,PID:10000,level:j})
			 	  			else nodeArray.push({ID:seq,NAME:nodename,PID:parentCode,level:j})
			 	  		};
			 	  	};
			 };
		 return nodeArray;
	},
	getTreeNodeArray : function(querysql) {
		var ds_map = new AI.JsonStore({
		    sql: querysql,
		    pageSize:-1,
		    key:"XMLID"
		  });
		 
		var nodeDataArray = [];

		for (var i = 0; i < ds_map.getCount(); i++) {
			var r = ds_map.getAt(i);
			nodeDataArray.push(r.data);
		}
		;
		// console.log(ds_map.data );
		console.log(nodeDataArray);
		return nodeDataArray;
	}
})
AI.MainSheet = Event.$extend({
	headId:'topMenu',
	contentId:'maintabcontent',
	__init__ : function(options) {
		if(options.headId) this.headId=options.headId;
		if(options.contentId) this.contentId=options.contentId;
		this.init(options);
	},
	init:function(options){
		
	},
	bindEvent:function(){
      
	},
	buildTabHead:function(tabId,title,url,canClose,showDefault,iconURI,noResizeHeadOnClose){
		var self = this;
		if(canClose) 
			newLi = $('<li class=""><a href="#'+tabId+'" data-toggle="tab">'+title+'<i class="close  icon-close"></i></a></li>').appendTo($('#'+this.headId))
		else 
			newLi = $('<li class=""><a href="#'+tabId+'" data-toggle="tab">'+title+'</a></li>').appendTo($('#'+this.headId));
 
		$(newLi).find('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			 
			 var tabpanId=$(e.target).attr("href");
			  
			 var hasload=$(tabpanId).attr("hasload");
			 if(hasload=='n'){
				 var _url=$(tabpanId).attr("url",url);
				 $(tabpanId).find("iframe").attr("src",url);
			     $(tabpanId).attr("hasload",'y');
			 }
		});
		$(newLi).find(".close").click(function(){
	 		 var tabId = $(this).parent().attr("href");
	  		 tabId=tabId.replace('#','');
	  		 $(this).parent().parent().remove();
			 $("#"+tabId).remove();
			 var length=$("#"+self.headId+" li").length;
			 var middleMaxWidth=$(window).width()-$("#left-logo").width()-$("#right-logo").width()-1;
			 var liLength=middleMaxWidth/length;
	 		 if(liLength>138){	 				
	 			$("#"+self.headId+">li").css('width','');	
	 			$("#"+self.headId+">li").css('text-overflow','');	
	 			$("#"+self.headId+">li").css('overflow','');
	 			$("#"+self.headId+">li").css('white-space','');
	 			$("#"+self.headId+">li").css('padding-right','');
	 			$(".li_span_text_tag").removeClass("li_span_text");	 			
	 			//$("#topMenu>i").removeClass("close_more");
	 		 }else{
	 		 	if(!noResizeHeadOnClose) {
	 		 		$("#"+self.headId+">li").css('width',middleMaxWidth/length-1);
	 		 	}
	 			$(".li_span_text_tag").css('width',liLength-28);
	 		 }
			 if($("#"+self.headId+">li").length==0) {
				$("#btn_desktop").click();
			 }
			 else {
				$("#"+self.headId+">li:last-child").find("a").click();
			 }
 		 }) ;
	},
	buildTabContent:function(tabId,url,showDefault){
		 
		var tabpan = $('<div class="tab-pane" id="'+tabId+'"></div> ').appendTo($('#'+this.contentId));
		if(url){
			$(tabpan).attr("url",url)
			.append(' <iframe id="iframe_'+tabId+'" src=""  width="100%" height="100%" frameborder="0" border="0" marginwidth="0" marginheight="0" onLoad="iFrameHeight(\'iframe_'+tabId+'\')"> </iframe>')
		}
		$(tabpan).attr("hasload",'n');
		if(showDefault==true){
	    	$(tabpan).find("iframe").attr("src",url);
	    	$(tabpan).attr("hasload",'y');
	    }
		
	},
	addTabSheet:function(id,title,url,canClose,showDefault,iconURI,noResizeHeadOnClose){
		if(typeof(canClose)=="undefined") canClose=true;
		if(typeof(showDefault)=="undefined") showDefault=true;
		if(id){
			id=id.replaceAll(".","_").replace("$","").replace("{","").replace("}","");
			
			var hrefArray=$('#'+MainSheet.headId).find("li a[href='#"+id+"']");
			
			if(hrefArray.length>0){
				hrefArray[0].click();
				return true;
			};
		}
		var tabId;
		if(title=='搜索'||title=='我的信息')canClose=true;
		if(id) tabId=id
		else tabId='tab_'+ai.guid();
		
	 	this.buildTabHead(tabId,title,url,canClose,showDefault,iconURI,noResizeHeadOnClose);
	 	this.buildTabContent(tabId,url,false);
	 	if(showDefault==true) {
	 		$("#"+this.headId).find('a[href="#'+tabId+'"]').click();
	 	}
	},
	removeTabSheet:function(id){
	}
});
function iFrameHeight(iframid) { 
	if(!iframid) return false;
	var ifm= document.getElementById(iframid);   
	var subWeb = document.frames ? document.frames[iframid].document : ifm.contentDocument;   
	if(ifm != null && subWeb != null) {
		if(subWeb.body.scrollHeight>10){
			ifm.height = subWeb.body.scrollHeight;
			//ifm.height = subWeb.body.scrollHeight+20;
			ifm.width = subWeb.body.scrollWidth;
		}
	   //ifm.height = subWeb.body.scrollHeight;
	   //ifm.width = subWeb.body.scrollWidth;
	};
	console.log(subWeb.body.scrollHeight);
}; 
///构建购物车
function buildShopCart(){
	
	var htmltpl='<div id="flyItem" class="fly_item" data-center="495,-75" style="left: 814px; top: 323px; visibility: hidden; -webkit-transform: translate(495px, -75px);"><img src="/'+contextPath+'/dacp-res/images/u95.png" width="40" height="40"></div>'
//				+'<a href="#" id="shopCart" class="">'
//				+'<i class="icon-basket-loaded"></i>'
//				+'<span class="badge badge-sm bg-danger count" style="display: inline-block;position: absolute;top: -5px;font-size: 8px;">3</span>'
//				+'</a>';
	$(htmltpl).appendTo($("body"));
	var eleFlyElement = document.querySelector("#flyItem"), eleShopCart = document.querySelector("#shopCart");
	var numberItem = 0;
	  var myParabola = funParabola(eleFlyElement, eleShopCart, {
	  speed: 400, //抛物线速度
	  curvature: 0.0008, //控制抛物线弧度
	  complete: function() {
	    eleFlyElement.style.visibility = "hidden";
	    eleShopCart.querySelector("span").innerHTML = numberItem;
//	    var selObjTpl=' <li class="list-group-item"> <div class="clear">{OBJNAME} </div> <span class="pull-right"> a href="#"><i class="fa fa-times icon-muted fa-fw"></i></a> </span></li>';
//	    var objname=itemStore.curRecord.get(metaInfo.keyfield);
//	    var html=selObjTpl.replace("{OBJNAME}",objname);
//	    $("#shopCartList").append(html);
	 
	  }
	});
	if (eleFlyElement && eleShopCart) {
	  //[].slice.call(document.getElementsByClassName("icon-basket")).forEach(function(button) {		
	  [].slice.call(document.getElementsByName("addMyFav")).forEach(function(button) {
	    button.addEventListener("click", function(event) {
	    	console.log($(this).parent().parent().parent().parent().attr("id")+","+$(this).parent().parent().parent().parent().attr("title"));
	    	var objid=$(this).parent().parent().parent().parent().attr("id");
	    	var objname=$(this).parent().parent().parent().parent().attr("title");
	    	if(!shopCartItems[objid]){
	    		shopCartItems[objid]=objname;
	    		numberItem++;
	    	}
	    	else{
	    		return false;
	    	}
	      // 滚动大小
	      var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft || 0,
	          scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
	      console.log(scrollLeft,scrollTop);
	      eleFlyElement.style.left = event.clientX + scrollLeft + "px";
	      eleFlyElement.style.top = event.clientY + scrollTop + "px";
	      eleFlyElement.style.visibility = "visible";
	      
	      // 需要重定位
	      myParabola.position().move();
	      return false;
	    });
	    return false;
	  });
	};
	 
	$("#shopCart").popover({
		  content:function(){
			  var content='<section class="panel panel-info" style="width:270px"><ul class="list-group" id="shopCartList">';
			  var selObjTpl=' <li class="list-group-item" id="{objid}"> {OBJNAME}</li>';
			  
			  for(var key in shopCartItems){
				  var objname=shopCartItems[key];
				  var Itemhtml=selObjTpl.replace("{OBJNAME}",objname);
				  Itemhtml=Itemhtml.replace("{objid}",key);
				  content+=Itemhtml;
			  }
			  content+='</ul>';
			  content+='<div class="panel-footer">'
			  content+='<button type="button" class="btn btn-default btn-xs">清空</button>';
			  content+='<button type="button" class="btn btn-default btn-xs">申请</button>';
			  content+='<button type="button" class="btn btn-default btn-xs">分析</button>';
				 
			  content+='</section>';
			  return content;
		  },
	      html:'true',
	      placement:'left',
	      title:'选择的对象',show:true,trigger: 'manual'})
	           .on("mouseenter", function () {
	                    var _this = this;
	                    $(this).popover("show");
	                    $(this).siblings(".popover").on("mouseleave", function () {
	                        $(_this).popover('hide');
	                    });
	                }).on("mouseleave", function () {
	                    var _this = this;
	                    setTimeout(function () {
	                        if (!$(".popover:hover").length) {
	                            $(_this).popover("hide")
	                        }
	                    }, 100);
	                });
}

///底部滚动栏
function installBottomSideButton(){
	var isWebKit = navigator.userAgent.indexOf('WebKit') !== -1;
	scrollElement = isWebKit ? document.body : document.documentElement;
	var html=['<div class="m_side_btns" id="m_side_btns" style="bottom: 20px;position: fixed;right: 10px;border: 1px solid #eee;border-top: none;"> ',
'   <a class="side_btn toTopBtn" href="#" id="returnToTop" style="display: none;">回 到顶 部</a> ',
'   <a class="side_btn surveyBtn" href="#">推荐好友</a> ',
'   <a class="side_btn surveyBtn" id="shopCart" href="#"><span class="badge badge-sm bg-danger count" style="display: inline-block;position: absolute;right: -5px;font-size: 8px;">3</span>购物车</a> ',
'   <a class="side_btn helpBtn" href="#">帮 助中 心</a> ',
'   <a class="side_btn fbBtn" href="#">意 见反 馈</a> ',
'  </div>'].join("");
$(html).appendTo($("body"));

var sideBtns = document.getElementById('m_side_btns'),
    toTopBtn = document.getElementById('returnToTop'),
    sideBtnsBottomLimit = document.getElementById('g_ft');
    isTopBtnVisible = false,
    recent = document.getElementById('g_recent'),
    popupBar = document.getElementById('popupBar');
window.addEventListener('scroll',function(){
    var scrollTop = scrollElement.scrollTop,
        totalTop = scrollTop + window.innerHeight,
        bottomLimit = sideBtnsBottomLimit.offsetTop;
    if(scrollTop>200 && !isTopBtnVisible)
        toTopBtn.style.display = 'block';
    else if(scrollTop<=200){
        toTopBtn.style.display = 'none';
        isTopBtnVisible = false;
    }
    if(totalTop>=bottomLimit){
        if(sideBtns.isBottomFixed)
            sideBtns.isBottomFixed = false;
        sideBtns.style.bottom = (totalTop - bottomLimit + 20)+'px';
    }else if(!sideBtns.isBottomFixed){
        sideBtns.isBottomFixed = true;
        sideBtns.style.bottom = '20px';
    }
});
if(recent){
    var recentToTop = recent.offsetTop,
        isRecentFixed = false;
    window.addEventListener('scroll',function(){
        if(!isRecentFixed && scrollElement.scrollTop>=recentToTop){
            isRecentFixed = true;
            if(popupBar)
                recent.className += ' g_recent_follow';
            else
                recent.className += ' g_recent_followTop';
        }else if(isRecentFixed && scrollElement.scrollTop<recentToTop){
            isRecentFixed = false;
            recent.className = 'g_recent';
        }
    },false);
}
if(popupBar){
    var popbarBtns = popupBar.getElementsByTagName('a'),
        popbarAnchors = document.getElementById('g_detail').getElementsByTagName('h3'),
        popbarToTops = [];
    for(i = 1;i<6;i++){
        popbarToTops.push(popbarAnchors[i].offsetTop);
    }
    window.addEventListener('scroll',(function(){
        var scrollTop,
            popbarToTop = popupBar.offsetTop;
            popbarBtns = window.popbarBtns,
            isPopbarFixed = false,
            isSet = [true],
            crtBtn = 0;
            toTops = window.popbarToTops;
        function setBtn(btn){
            popbarBtns[crtBtn].className = 'popbar_btn';
            popbarBtns[btn].className += ' popbar_btn_crt';
            isSet[crtBtn] = false;
            isSet[btn] = true;
            crtBtn = btn;
        }

        return function(){
            scrollTop = scrollElement.scrollTop + 44;
            if(!isPopbarFixed && scrollTop>=popbarToTop){
                isPopbarFixed = true;
                popupBar.className += ' popup_bar_fixed';
            }else if(isPopbarFixed && scrollTop<popbarToTop){
                isPopbarFixed = false;
                popupBar.className = 'popup_bar';
            }
            if(scrollTop<toTops[1]){
                if(!isSet[0])
                    setBtn(0);
            }else if(scrollTop<toTops[2]){
                if(!isSet[1])
                    setBtn(1);
            }else if(scrollTop<toTops[3]){
                if(!isSet[2])
                    setBtn(2);
            }else if(scrollTop<toTops[4]){
                if(!isSet[3])
                    setBtn(3);
            }else if(scrollTop>=toTops[4]){
                if(!isSet[4])
                    setBtn(4);
            }
        }
    })(),false);
    for(i = 0;i<5;i++){
        popbarBtns[i].index = i;
        popbarBtns[i].onclick = function(){
            $(scrollElement).stop().animate({scrollTop:popbarToTops[this.index]});
        }
    }
}
$(toTopBtn).click(function(){
    $(scrollElement).animate({scrollTop: '0px'}, 600);
});
$("#m_side_btns .helpBtn").click(function(){
	 alert('kkk');
});
};
function dealUrl(url,param){
	  if(!url) return url;
	  if(!param) param={};
	  param['contextPath']=contextPath;
	  param['TEAMCODE']=paramMap.TEAMCODE;
	   for(var key in param){  
		   url = url.replace('{'+key+'}',param[key]);
    }  
	  return url;
 };